/**
 * @author:稀饭
 * @time:上午12:44:01
 * @filename:ConnectionWork.java
 */
package service;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import data.DataClass;

public class ConnectionWork {
	public HttpURLConnection getConn(String url, String referString) {

		HttpURLConnection conn = null;
		URL realUrl = null;
		try {
			realUrl = new URL(url);
		} catch (MalformedURLException e2) {
			// TODO Auto-generated catch block
//			e2.printStackTrace();
		}
		// 打开和URL之间的连接
		try {
			conn = (HttpURLConnection) realUrl.openConnection();
		} catch (IOException e2) {
			// TODO Auto-generated catch block
//			e2.printStackTrace();
		}
		// 设置通用的请求属性
		conn.setRequestProperty("X-Requested-With", "XMLHttpRequest");
		conn.setRequestProperty("Referer", referString);
		conn.setRequestProperty("accept", "*/*");
		conn.setRequestProperty("connection", "Keep-Alive");

		conn.setRequestProperty("user-agent",
				new DataClass().user_agent[(int) (Math.random() * 100) % 8]);
		conn.setDoOutput(true);
		conn.setDoInput(true);
		conn.setConnectTimeout(30 * 1000);
		conn.setReadTimeout(30 * 1000);
		return conn;
	}
}
